package aplikasirawatinap;


import Controller.Generate_md5;
import Service.Koneksi;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Nikko Agustino
 */
public class Tampil_User extends javax.swing.JFrame {
    private Integer row;
    public Connection conn;
    PreparedStatement psmt;
    private JTable jTabel = new JTable();
    String select="SELECT *FROM users where kategori = 'user' ORDER BY nik ASC";
    String nik;
    String s,t,u,v,w,x,y,z;
    private int ok;

    /**
     * Creates new form NewJFrame
     */
    public Tampil_User() {
        setTitle("DAFTAR USER");
        initComponents();
        tampilkandata();
        tx_nik2.setVisible(false);
    }
    
   private void tampilkandata() {
        DefaultTableModel isitabel = new DefaultTableModel();
        isitabel.addColumn("NO");
        isitabel.addColumn("NIK");
        isitabel.addColumn("Gender");
        isitabel.addColumn("Nama_Dpn");
        isitabel.addColumn("Nama_Bel");
        isitabel.addColumn("Password");
        isitabel.addColumn("Jabatan");
        isitabel.addColumn("Email");
        
        try {
           conn=Koneksi.getConnection();
           PreparedStatement statement = conn.prepareStatement(select);
           ResultSet rs =statement.executeQuery(select);
           int no=1;
            while (rs.next()) {
                isitabel.addRow(new Object[]{no,rs.getString("nik"),rs.getString("Gender"),rs.getString("first_name")
                                                            ,rs.getString("last_name"),rs.getString("password")
                                                            ,rs.getString("kategori"),rs.getString("email")});
                no++;
            }
            jTable2.setModel(isitabel);
        } catch (Exception e) {
        }
   }
   private void klikTabel(JTable jTabel) {
        jTabel.setRowSelectionAllowed(true);
        row = jTabel.getSelectedRow();
        String kolom1 = jTabel.getValueAt(row,0).toString();
        String kolom2 = jTabel.getValueAt(row,1).toString();
        String kolom3 = jTabel.getValueAt(row,2).toString();
        String kolom4 = jTabel.getValueAt(row,3).toString();
        String kolom5 = jTabel.getValueAt(row,4).toString();
        String kolom6 = jTabel.getValueAt(row,5).toString();
        String kolom7 = jTabel.getValueAt(row,6).toString();
        String kolom8 = jTabel.getValueAt(row,7).toString();
        
        tx_nik.setText(kolom2);
        tx_nik.setEnabled(false);
        tx_nik2.setText(kolom2);
        tx_nik2.setEnabled(false);
        combo_gender.setSelectedItem(kolom3);
        combo_gender.setEnabled(false);
        tx_fname.setText(kolom4);
        tx_fname.setEnabled(false);
        tx_lname.setText(kolom5);
        tx_lname.setEnabled(false);
        tx_pass.setText(kolom6);
        tx_pass.setEnabled(false);
        combo_kate.setSelectedItem(kolom7);
        combo_kate.setEnabled(false);
        tx_email.setText(kolom8);
        tx_email.setEnabled(false);
   }
   
   private void kondisiHapus() {
       nik = tx_nik.getText();
       ok = JOptionPane.showConfirmDialog(null, "Anda yakin akan menghapus data ini?", "Konfirmasi", JOptionPane.OK_CANCEL_OPTION);
        if (ok == 0){
                try {
		Statement st = Koneksi.getConnection().createStatement();
                st.executeUpdate(
                " delete from users where nik ='"+ nik +"'");
                tampilkandata();
                JOptionPane.showMessageDialog(this, "Data berhasil dihapus");
                }
                catch (SQLException ex) {
                    JOptionPane.showMessageDialog(this,"Data gagal dihapus: " +ex);
                    
                }
            }
        

            
   }
   public void kondisiEdit()
   {
      try{
          s = tx_nik.getText();
          t = (String) combo_gender.getSelectedItem();
          u = tx_fname.getText();
          v = tx_lname.getText();
          w = tx_pass.getText();
          Generate_md5 get = new Generate_md5();
          String key = get.md5(w);
          x = (String) combo_kate.getSelectedItem();
          y = tx_email.getText();
          z = tx_nik2.getText();
          if(tx_nik.getText().equals("")){JOptionPane.showMessageDialog(null,"NIK harus diisi", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           else if(tx_fname.getText().equals("")){JOptionPane.showMessageDialog(null,"Nama Depan harus diisi", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           else if(tx_lname.getText().equals("")){JOptionPane.showMessageDialog(null,"Nama Belakang harus diisi", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           else if(tx_pass.getText().equals("")){JOptionPane.showMessageDialog(null,"Password Harus Diisi", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           else if(tx_pass.getText().length()<5){JOptionPane.showMessageDialog(null,"Password tidak boleh kurang dari 5 digit", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           //else if(!tx_rpass.getText().equals(tx_pass.getText())){JOptionPane.showMessageDialog(null,"Re-Pass tidak sama", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           else if(tx_email.getText().equals("")){JOptionPane.showMessageDialog(null,"Email Harus Diisi", "ERROR", JOptionPane.PLAIN_MESSAGE);}
           else{
                
                conn = Koneksi.getConnection();
                Statement stm=conn.createStatement(); 
                //Statement st = Koneksi.getConnection().createStatement();  
                stm.executeUpdate(
                    "update users set "+
                    "nik = "+"'"+ s +"', "+
                    "Gender = "+"'"+ t +"', "+
                    "first_name = "+"'"+ u +"', "+
                    "last_name = "+"'"+ v +"', "+
                    "password = "+"'"+ key +"', "+
                    "kategori = "+"'"+ x +"', "+
                    "email = "+"'"+ y +"' "+
                    "where nik = '"+ z +"'"); 
               tampilkandata();
               JOptionPane.showMessageDialog(this,"Data berhasil diperbaharui");
                
           }
         
        }catch (SQLException ex) {
                    JOptionPane.showMessageDialog(this, "Data gagal diperbaharui! : " +ex);
        }
   }
   
   public void cari() {
       DefaultTableModel isitabel = new DefaultTableModel();
        isitabel.addColumn("NO");
        isitabel.addColumn("NIK");
        isitabel.addColumn("Gender");
        isitabel.addColumn("Nama_Dep");
        isitabel.addColumn("Nama_Bel");
        isitabel.addColumn("Password");
        isitabel.addColumn("Jabatan");
        isitabel.addColumn("Email");
        try {
           conn=Koneksi.getConnection();
           String search = "Select * from users where nik like '%" + tx_search.getText() + "%'" +
                         "or first_name like '%" + tx_search.getText() + "%'";
           PreparedStatement statement = conn.prepareStatement(search);
           ResultSet rs =statement.executeQuery(search);
           int no=1;
            while (rs.next()) {
                isitabel.addRow(new Object[]{no,rs.getString("nik"),rs.getString("Gender"),rs.getString("first_name")
                                                            ,rs.getString("last_name"),rs.getString("password")
                                                            ,rs.getString("kategori"),rs.getString("email")});
                no++;
            }
            jTable2.setModel(isitabel);
        } catch (Exception e) {
      }
   }
    
   public void clearText() {
       tx_nik.setText("");
       combo_gender.setSelectedItem("");
       tx_fname.setText("");
       tx_lname.setText("");
       tx_pass.setText("");
       combo_kate.setSelectedItem("");
       tx_email.setText("");
   }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        b_simpan = new javax.swing.JButton();
        b_edit = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        btnHapus = new javax.swing.JButton();
        lb_nik = new javax.swing.JLabel();
        tx_nik = new javax.swing.JTextField();
        b_add = new javax.swing.JButton();
        lb_fname = new javax.swing.JLabel();
        tx_fname = new javax.swing.JTextField();
        lb_lname = new javax.swing.JLabel();
        lb_password = new javax.swing.JLabel();
        lb_kategori = new javax.swing.JLabel();
        tx_lname = new javax.swing.JTextField();
        lb_email = new javax.swing.JLabel();
        tx_pass = new javax.swing.JTextField();
        tx_email = new javax.swing.JTextField();
        combo_kate = new javax.swing.JComboBox();
        tx_nik2 = new javax.swing.JTextField();
        lb_gender = new javax.swing.JLabel();
        combo_gender = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        tx_search = new javax.swing.JTextField();
        b_search = new javax.swing.JButton();
        b_viewall = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMnKembali = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);
        setType(java.awt.Window.Type.POPUP);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTable2MousePressed(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("DAFTAR USER");

        b_simpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/save.png"))); // NOI18N
        b_simpan.setText("SIMPAN");
        b_simpan.setEnabled(false);
        b_simpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_simpanActionPerformed(evt);
            }
        });

        b_edit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/edit.png"))); // NOI18N
        b_edit.setText("EDIT");
        b_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_editActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/view_user2.png"))); // NOI18N

        btnHapus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/trash.png"))); // NOI18N
        btnHapus.setText("HAPUS");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        lb_nik.setText("NIK");

        tx_nik.setEditable(false);

        b_add.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/add_user.png"))); // NOI18N
        b_add.setText("ADD DATA BARU");
        b_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_addActionPerformed(evt);
            }
        });

        lb_fname.setText("Nama Depan");

        tx_fname.setEditable(false);

        lb_lname.setText("Nama Belakang");

        lb_password.setText("Password");

        lb_kategori.setText("Kategori");

        tx_lname.setEditable(false);

        lb_email.setText("Email");

        tx_pass.setEditable(false);

        tx_email.setEditable(false);

        combo_kate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "User", " " }));
        combo_kate.setEnabled(false);
        combo_kate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_kateActionPerformed(evt);
            }
        });

        lb_gender.setText("Gender");

        combo_gender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
        combo_gender.setEnabled(false);

        jLabel3.setText("Search User Berdasarkan NIK / First Name");

        b_search.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/search.png"))); // NOI18N
        b_search.setText("SEARCH");
        b_search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_searchActionPerformed(evt);
            }
        });

        b_viewall.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/view_user.png"))); // NOI18N
        b_viewall.setText("VIEW ALL");
        b_viewall.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_viewallActionPerformed(evt);
            }
        });

        jMenuBar1.setBackground(new java.awt.Color(236, 236, 236));

        jMnKembali.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/back.png"))); // NOI18N
        jMnKembali.setToolTipText("Menu Utama");
        jMnKembali.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMnKembaliMousePressed(evt);
            }
        });
        jMenuBar1.add(jMnKembali);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lb_nik)
                                    .addComponent(lb_fname)
                                    .addComponent(lb_lname)
                                    .addComponent(lb_gender))
                                .addGap(38, 38, 38)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tx_nik, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                    .addComponent(tx_fname, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                    .addComponent(tx_lname, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                    .addComponent(combo_gender, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(3, 3, 3)
                                .addComponent(tx_nik2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lb_email)
                                            .addComponent(lb_kategori))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(combo_kate, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(tx_email, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lb_password)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(tx_pass, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tx_search, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(b_search))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(b_add)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(b_viewall))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 613, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(b_simpan)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(b_edit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnHapus)))
                        .addGap(0, 48, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tx_pass, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lb_nik)
                                .addComponent(tx_nik, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lb_password)
                                .addComponent(tx_nik2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_kategori)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lb_gender)
                                .addComponent(combo_gender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(combo_kate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_email)
                    .addComponent(lb_fname)
                    .addComponent(tx_fname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tx_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_lname)
                    .addComponent(tx_lname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b_add)
                    .addComponent(b_viewall))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tx_search, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(b_search))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b_simpan)
                    .addComponent(b_edit)
                    .addComponent(btnHapus))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
    
    }//GEN-LAST:event_formWindowActivated

    private void jMnKembaliMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMnKembaliMousePressed
        // TODO add your handling code here:
        new AdminForm().setVisible(true);
        dispose();
    }//GEN-LAST:event_jMnKembaliMousePressed

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
        kondisiHapus();
        
    }//GEN-LAST:event_btnHapusActionPerformed

    private void jTable2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MousePressed
        // TODO add your handling code here:
        klikTabel(jTable2);
    }//GEN-LAST:event_jTable2MousePressed

    private void b_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_addActionPerformed
        // TODO add your handling code here:
        new Add_User().setVisible(true);
        dispose();
    }//GEN-LAST:event_b_addActionPerformed

    private void combo_kateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_kateActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_combo_kateActionPerformed

    private void b_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_editActionPerformed
        // TODO add your handling code here:
        b_simpan.setEnabled(true);
        tx_nik.setEnabled(true);
        combo_gender.setEnabled(true);
        tx_fname.setEnabled(true);
        tx_lname.setEnabled(true);
        tx_pass.setEnabled(true);
        //combo_kate.setEnabled(true);
        tx_email.setEnabled(true);
        
        tx_nik.setEditable(true);
        combo_gender.setEnabled(true);
        tx_fname.setEditable(true);
        tx_lname.setEditable(true);
        tx_pass.setEditable(true);
        //combo_kate.setEditable(true);
        tx_email.setEditable(true);
        
    }//GEN-LAST:event_b_editActionPerformed

    private void b_simpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_simpanActionPerformed
        // TODO add your handling code here:
        kondisiEdit();
        clearText();
        b_simpan.setEnabled(false);
        tx_nik.setEnabled(false);
        combo_gender.setEnabled(false);
        tx_fname.setEnabled(false);
        tx_lname.setEnabled(false);
        tx_pass.setEnabled(false);
        combo_kate.setEnabled(false);
        tx_email.setEnabled(false);
        
        tx_nik.setEditable(false);
        combo_gender.setEnabled(false);
        tx_fname.setEditable(false);
        tx_lname.setEditable(false);
        tx_pass.setEditable(false);
        combo_kate.setEditable(false);
        tx_email.setEditable(false);
        
    }//GEN-LAST:event_b_simpanActionPerformed

    private void b_searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_searchActionPerformed
        // TODO add your handling code here:
        cari();
    }//GEN-LAST:event_b_searchActionPerformed

    private void b_viewallActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_viewallActionPerformed
        // TODO add your handling code here:
        tampilkandata();
    }//GEN-LAST:event_b_viewallActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        new AdminForm().setVisible(true);
        dispose();
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tampil_User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tampil_User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tampil_User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tampil_User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Tampil_User().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b_add;
    private javax.swing.JButton b_edit;
    private javax.swing.JButton b_search;
    private javax.swing.JButton b_simpan;
    private javax.swing.JButton b_viewall;
    private javax.swing.JButton btnHapus;
    private javax.swing.JComboBox combo_gender;
    private javax.swing.JComboBox combo_kate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu jMnKembali;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    private javax.swing.JLabel lb_email;
    private javax.swing.JLabel lb_fname;
    private javax.swing.JLabel lb_gender;
    private javax.swing.JLabel lb_kategori;
    private javax.swing.JLabel lb_lname;
    private javax.swing.JLabel lb_nik;
    private javax.swing.JLabel lb_password;
    private javax.swing.JTextField tx_email;
    private javax.swing.JTextField tx_fname;
    private javax.swing.JTextField tx_lname;
    private javax.swing.JTextField tx_nik;
    private javax.swing.JTextField tx_nik2;
    private javax.swing.JTextField tx_pass;
    private javax.swing.JTextField tx_search;
    // End of variables declaration//GEN-END:variables
}
